import java.util.Scanner;

public class FingerGuess {

    public static void main(String[] args) {
        System.out.println("请输入参与猜拳的人数(2~5)：");
        Scanner sc = new Scanner(System.in);
        int number = sc.nextInt();
        int temp = number;
        int[] players = new int[number];

        // 初始化4 表示没出拳的情况
        for (int i = 0; i < number; i++) {
            players[i] = 4;
        }

        while (true) {

            // 玩家出拳
            if (players[0] != 0) {
                System.out.println("请出拳：(1：剪刀、2：石头、3：布)");
                players[0] = sc.nextInt();
            }
            // 计算机出拳
            for (int i = 1; i < number; i++) {
                if (players[i] != 0)
                    players[i] = RandomInt.randomInt(1, 4);
            }

            print(players, number);

            for (int i = 0; i < number; i++) {
                int flag = 0;

                // 0表示 已经出局
                if (players[i] == 0)
                    continue;
                for (int j = 0; j < number; j++) {
                    if ((players[i] == 1 && players[j] == 3) || (players[i] == 2 && players[j] == 1 || (players[i] == 3 && players[j] == 2))) {
                        // 赢过就不会出局
                        flag = 1;
                        break;
                    } else if ((players[i] == 1 && players[j] == 2) || (players[i] == 2 && players[j] == 3) || (players[i] == 3 && players[j] == 1)) {
                        //当玩家输过记flag改为-1
                        flag = -1;
                    }
                }

                if (flag == -1) {                                         //未赢过且输过 出局玩家减少
                    players[i] = 0;
                    System.out.println(i + "号出局");
                    temp--;
                }
            }


            if (temp == 1) {
                for (int k = 0; k < number; k++) {
                    if (players[k] != 0)
                        System.out.println("最后胜出的是" + k + "号玩家");
                }
                break;
            }

        }
    }

    private static void print(int[] arr, int number) {
        System.out.println("************************");
        for (int i = 0; i < number; i++) {
            switch (arr[i]) {
                case 1:
                    System.out.println(i + "号出的剪刀");
                    break;
                case 2:
                    System.out.println(i + "号出的石头");
                    break;
                case 3:
                    System.out.println(i + "号出的布");
                    break;
                case 0:
                    System.out.println(i + "号已出局");
                    break;
            }
        }
        System.out.println("************************");
    }
}
